'use strict';

module.exports = function (grunt) {
  require('load-grunt-tasks')(grunt);
  require('time-grunt')(grunt);

  grunt.loadTasks("./grunt-tasks/neuter");
  grunt.loadTasks("./grunt-tasks/compass");

  grunt.initConfig({
    yeoman: {
      app: grunt.option('app')
    },
    watch: {
        neuter_cms: {
            files: ['cms/scripts/**/*.js', 'ext/components/*/cms/**/*.js'],
            tasks: ['neuter_customized:cms']
        },
        neuter_client: {
            files: [
                'client/scripts/**/*.js'
            ],
            tasks: ['neuter_customized:client']
        },
        neuter_customized: {
            files: [
                'ext/themes/*/widget/**/*.js',
                'ext/components/*/client/**/*.js'
            ],
            tasks: ['neuter_customized_app:app']
        },

        compass_cms: {
            files: ['cms/styles/{,*/}*.{scss,sass}'],
            tasks: ['compass:cms']
        },
        compass_client: {
            files: ['client/styles/{,*/}*.{scss,sass}'],
            tasks: ['compass:client']
        },
        compass_customized: {
            files: [
                'ext/themes/*/style/*.{scss,sass}',
                'ext/themes/*/widget/**/*.{scss,sass}',
                'ext/components/*/client/**/*.{scss,sass}'
            ],
            tasks: ['compass_customized:app']
        }
    },

      neuter_customized: {
        cms: {
            options: {
                filepathTransform: function (filepath) {
                    return 'cms/scripts/' + filepath;
                }
            },
            src: 'cms/scripts/requires.js',
            dest: '.tmp/cms/scripts'
        },
        client: {
            options: {
                filepathTransform: function (filepath) {
                    return 'client/scripts/' + filepath;
                }
            },
            src: 'client/scripts/requires.js',
            dest: '.tmp/client/scripts'
        }
    },
      neuter_customized_app: {
          app: {
              options: {
                  filepathTransform: function (filepath) {
                      return filepath;
                  }
              },
              src: 'pending',
              dest: 'pending',
              app: '<%= yeoman.app %>'
          }
      },
    compass: {
        options: {
            debugInfo: true,
            importPath: 'bower_components',
            httpGeneratedImagesPath: '../img/generated',
            httpFontsPath: 'fonts',
            relativeAssets: false
        },
        cms: {
            options: {
                sassDir: 'cms/styles',
                cssDir: '.tmp/cms/styles',
                generatedImagesDir: '.tmp/cms/img/generated',
                imagesDir: 'cms/img',
                httpImagesPath: '../../../cms/img'
            }
        },
        client: {
            options: {
                sassDir: 'client/styles',
                cssDir: '.tmp/client/styles',
                generatedImagesDir: '.tmp/client/img/generated',
                imagesDir: 'client/img',
                httpImagesPath: '../../../client/img'
            }
        }
    },
      compass_customized: {
          options: {
              debugInfo: true,
              importPath: 'bower_components',
              httpGeneratedImagesPath: '../img/generated',
              relativeAssets: false
          },
          app: {
              options: {
                  sassDir: 'pending-sass-dir',
                  cssDir: '.tmp/client/styles',

                  imagesDir: 'pending-theme',
                  generatedImagesDir: '.tmp/client/img/generated',
                  fontsDir: 'pending-fonts-dir'
              }
          }
      }
//      replace: {
//          theme: {
//              src: '.tmp/client/styles/*.css',
//              overwrite: true,
//              replacements: [{
//                  from: '',
//                  to: ''
//              }]
//          }
//      }
  });

    grunt.registerTask('default', [
        'neuter_customized:cms',
        'neuter_customized:client',
        'neuter_customized_app:app',
        'compass:cms',
        'compass:client',
        'compass_customized:app',
        'watch'
    ]);
};